package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class BambooGardenActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btnExitBambooGarden;
    private ImageView imgBamboo_1;
    private ImageView imgBamboo_2;
    private ImageView imgBamboo_3;
    private ImageView imgBamboo_4;
    private ImageView imgBamboo_5;
    private ImageView imgBamboo_6;
    private TextView txtTitle;

    private int bambooNum = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bamboo_garden);

        initView();
        txtTitle.setText("竹园");

        imgBamboo_1.setOnClickListener(this);
        imgBamboo_2.setOnClickListener(this);
        imgBamboo_3.setOnClickListener(this);
        imgBamboo_4.setOnClickListener(this);
        imgBamboo_5.setOnClickListener(this);
        imgBamboo_6.setOnClickListener(this);
        btnExitBambooGarden.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view instanceof ImageView) {
            changeBambooVisibility((ImageView) view);
        }
        if (view instanceof Button) {
            Intent intent = new Intent();
            intent.putExtra("bambooNum", bambooNum + "");
            setResult(2, intent);
            finish();
        }
    }

    private void changeBambooVisibility(ImageView imageView) {
        imageView.setVisibility(View.INVISIBLE);
        bambooNum++;
    }

    private void initView() {
        btnExitBambooGarden = findViewById(R.id.btn_exitBambooGarden);
        imgBamboo_1 = findViewById(R.id.img_bamboo_1);
        imgBamboo_2 = findViewById(R.id.img_bamboo_2);
        imgBamboo_3 = findViewById(R.id.img_bamboo_3);
        imgBamboo_4 = findViewById(R.id.img_bamboo_4);
        imgBamboo_5 = findViewById(R.id.img_bamboo_5);
        imgBamboo_6 = findViewById(R.id.img_bamboo_6);
        txtTitle = findViewById(R.id.txt_title);
    }
}